<?php
    $sessao = new Zend_Session_Namespace('Aluno');
?>
<div class="sc-cnt-publicacao">
    
    <div class="content-tb nowid e-cnt-men">
        
        <div class="tl-pag"><?php echo $this->data['PUL_NOM']; ?></div>
        
        <form id="form_pdr" method="post">
            <input type="hidden" id="ALU_ID" name="ALU_ID" value="<?php echo $sessao->aluno['ALU_ID']; ?>">
            <input type="hidden" id="PUL_ID" name="PUL_ID" value="<?php echo $this->data['PUL_ID']; ?>">
            
            <div class="lista-questoes">
            <?php
            
            if($this->data_enc == FALSE){
                
                // processo de verificação de encerramento, 15 em 15 segundos
                echo '<script> setInterval(function(){ proc_enc(); }, 15000); </script>';

                $query = 'SELECT SQL_CACHE * FROM PUBLICACAO_LISTA_GABARITO WHERE PUL_ID = '.$this->data['PUL_ID'];
                $result = $this->db->fetchAll($query);
                foreach($result as $row){

                    $query = 'SELECT SQL_CACHE * FROM PUBLICACAO_LISTA_RESPOSTA '
                            .' WHERE PUL_ID = '.$row['PUL_ID']
                            .' AND ALU_ID = '.$sessao->aluno['ALU_ID']
                            .' AND PLR_QST = '.$row['PLG_QST'];
                    $resp = $this->db->fetchRow($query);

                    $num_qst = $row['PLG_QST'];
                    
                    $html_row = '';
                    
                    $html_row .= '<div class="cnt_el">';
                    $html_row .= '<span class="cnt_num_qst">';
                    $html_row .= ' <input type="text" class="num_qst" name="q['.$num_qst.']" maxlength="3" value="'.$num_qst.'" readonly >';
                    
                    $html_row .= ' <input type="hidden" class="plg" name="g['.$num_qst.']" value="'.$row['PLG_ID'].'" readonly >';
                    $html_row .= ' <input type="hidden" class="dcp" name="d['.$num_qst.']" value="'.$row['DCP_ID'].'" readonly >';
                    
                    $html_row .= '</span>';

                    $html_row .= '<span class="cnt_qst_alt">';
 
                    if($resp['PLR_STA'] == 2){
                        $disabled = 'disabled="disabled"';
                        $readonly = 'readonly="readonly"';  
                    }else{
                        $disabled = '';
                        $readonly = '';
                    }
                    
                    $arr_qst = dominio::getAlternativa($row['PLG_TPO']);
                    
                    if(is_array($arr_qst)){
                        foreach($arr_qst as $key => $qst){
                            $checked = $key == $resp['PLR_ALT'] ? 'checked="checked"':'';
                            $class = $key == $resp['PLR_ALT'] ? 'btn_qst_alt_act':'';
                            $html_row .= '<input '.$disabled.' '.$checked.' type="radio" id="'.$num_qst.''.$key.'" class="rd_qst_alt" name="a['.$num_qst.']" value="'.$key.'" >';
                            $html_row .= ' &nbsp; <label for="'.$num_qst.''.$key.'"><span '.$disabled.' class="'.$class.' btn_qst_alt qst'.$num_qst.'" qst="'.$num_qst.'" val="'.$key.'">'.$qst.'</span></label> &nbsp; ';
                        }
                    } else if($row['PLG_TPO'] == 3){
                        $html_row .= '<input '.$readonly.' type="text" id="'.$num_qst.''.$key.'" class="num_int numero" maxlength="3" name="a['.$num_qst.']" value="'.$resp['PLR_ALT'].'" >';
                    }
                    $html_row .= '</span>';
                    
                    if($resp['PLR_STA'] == 2) $html_row .= '<span class="cnt_btn"><a href="javascript:void(0)" class="btn_cnf" qst="'.$num_qst.'" op="2">Alterar</a></span>';
                    else $html_row .= '<span class="cnt_btn"><a href="javascript:void(0)" class="btn_cnf" qst="'.$num_qst.'" op="1">Confirmar</a></span>';
                    
                    echo $html_row .= '</div>';  

                }
                
            } else{
             
                $query = 'SELECT SQL_CACHE * FROM PUBLICACAO_LISTA_GABARITO WHERE PUL_ID = '.$this->data['PUL_ID'];
                $result = $this->db->fetchAll($query);
                foreach($result as $row){

                    $query = 'SELECT SQL_CACHE * FROM PUBLICACAO_LISTA_RESPOSTA '
                            .' WHERE PUL_ID = '.$row['PUL_ID']
                            .' AND ALU_ID = '.$sessao->aluno['ALU_ID']
                            .' AND PLR_QST = '.$row['PLG_QST'];
                    $resp = $this->db->fetchRow($query);

                    $num_qst = $row['PLG_QST'];
                    
                    $html_row = '';
                    
                    $html_row .= '<div class="cnt_el">';
                    $html_row .= '<span class="cnt_num_qst">';
                    $html_row .= ' <input type="text" class="num_qst" name="q['.$num_qst.']" maxlength="3" value="'.$num_qst.'" readonly >';
                    
                    $html_row .= ' <input type="hidden" class="plg" name="g['.$num_qst.']" value="'.$row['PLG_ID'].'" readonly >';
                    $html_row .= ' <input type="hidden" class="dcp" name="d['.$num_qst.']" value="'.$row['DCP_ID'].'" readonly >';
                    
                    $html_row .= '</span>';

                    $html_row .= '<span class="cnt_qst_alt">';
 
                    $disabled = 'disabled="disabled"';
                    $readonly = 'readonly="readonly"';    
                    
                    $arr_qst = dominio::getAlternativa($row['PLG_TPO']);
                    
                    if(is_array($arr_qst)){
                        foreach($arr_qst as $key => $qst){
                            $checked = $key == $resp['PLR_ALT'] ? 'checked="checked"':'';
                            $class = $key == $resp['PLR_ALT'] ? 'btn_qst_alt_act':'';
                            $html_row .= '<input '.$disabled.' '.$checked.' type="radio" id="'.$num_qst.''.$key.'" class="rd_qst_alt" name="a['.$num_qst.']" value="'.$key.'" >';
                            $html_row .= ' &nbsp; <label for="'.$num_qst.''.$key.'"><span '.$readonly.' '.$disabled.' class="'.$class.' btn_qst_alt qst'.$num_qst.'" qst="'.$num_qst.'" val="'.$key.'">'.$qst.'</span></label> &nbsp; ';
                        }
                    } else if($row['PLG_TPO'] == 3){
                        $html_row .= '<input '.$readonly.' type="text" id="'.$num_qst.''.$key.'" class="num_int numero" maxlength="3" name="a['.$num_qst.']" value="'.$resp['PLR_ALT'].'" >';
                    }
                    $html_row .= '</span>';
                    
                    if($resp['PLR_ALT'] != $row['PLG_ALT']){
                        $html_row .= '<span class="cnt_alt_crt">Correta: <span class="alt">'.$row['PLG_ALT'].'</span></span>';
                    }else if($row['PLG_ALT'] > ''){
                        $html_row .= '<span class="cnt_alt_crt"><img src="'.$this->urlbase.'/public/media/images/correct.png" /></span>';
                    }                             
                   
                    echo $html_row .= '</div>';  
                }
            }
            ?>
                
            <?php /*
                <input name="Salvar" class="btn-frm" id="submitbutton" type="submit" value="Salvar">
            */ ?>
                
                <a class="btn-frm" href="<?php echo $this->baseUrl($this->modulo.'/'.$this->controller); ?>">Voltar</a>
            
            </div>
        </form>
    </div>
    
</div>
 
